package com.problem.leetcode;

import java.util.HashSet;

public class Problem3 {

    public static void main(String[] args) {
        int result = new Problem3().lengthOfLongestSubstring("pwwkew");
        System.out.println(result);


    }

    public int lengthOfLongestSubstring(String s) {
        int    start = 0;
        int    max   = 0;
        int    index = 0;
        char[] asnii = new char[128];
        if (s == null) {
            return 0;
        }

        for (; index < s.length(); ++index) {
            if (asnii[(int)s.charAt(index)] == s.charAt(index)) {
                if (s.charAt(index) != s.charAt(index - 1)) {
                    start = index - 1;
                } else {
                    continue;
                }
            } else {
                asnii[(int)s.charAt(index)] = s.charAt(index);
                max = max > (index - start) + 1? max : index - start + 1;

            }
        }
        return max;
    }

}
